package com.kuaimacode.kframework.agent.services.weather;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kuaimacode.kframework.agent.util.SessionUtil;
import com.kuaimacode.kframework.mybatis.mapper.agent.SysAgentWeatherMapper;
import com.kuaimacode.kframework.mybatis.models.agent.SysAgentWeather;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author anzy
 * @date 2019/04/08
 */
@Service
public class  WeatherService extends ServiceImpl<SysAgentWeatherMapper, SysAgentWeather> {




    	/**
    	 *  分页查找所有的数据
    	 * @param pageNum 当前页码，从1开始
    	 * @param pageSize  一页显示多少行
    	 * @return
    	 */
    	public PageInfo<SysAgentWeather> findAll(int pageNum, int pageSize) {
    		PageHelper.startPage(pageNum, pageSize);
    		QueryWrapper queryWrapper = new QueryWrapper();
    		queryWrapper.eq("agent_id", SessionUtil.getAgentId());
    		queryWrapper.orderByDesc("end_time");
    		List<SysAgentWeather> datas = baseMapper.selectList(queryWrapper);
    		return new PageInfo<SysAgentWeather>(datas);
    	}


	/**
	 * 获取分站配置的特殊天气（已生效的）
	 * @param agentId
	 * @return
	 */
	public List<SysAgentWeather> getRealTimeAgentWeather(String agentId){
		QueryWrapper<SysAgentWeather> qryWrapper = new QueryWrapper<>();
		qryWrapper.eq("agent_id", agentId);
		Date now = new Date();
		qryWrapper.ge("end_time",now);
		qryWrapper.le("start_time",now);
		return baseMapper.selectList(qryWrapper);
	}

	/**
	 * 获取分站配置的特殊天气
	 * @param agentId
	 * @return
	 */
	public List<SysAgentWeather> getAgentWeather(String agentId){
		QueryWrapper<SysAgentWeather> qryWrapper = new QueryWrapper<>();
		qryWrapper.eq("agent_id", agentId);

		return baseMapper.selectList(qryWrapper);
	}

}

